package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.ApplicationDao;
import cn.com.jtang.wedding.model.Application;

public class ApplicationDaoImpl extends BaseDaoImpl implements ApplicationDao {

	private static final String ID = "id";
	private static final String COMPANYNAME = "companyName";
	private static final String TELEPHONE = "telephone";
	private static final String CONTACT = "contact";
	private static final String ADDRESS = "address";
	
	@Override
	public List insertModelToList(Object object) {
		Application application = (Application)object;
		List args = new ArrayList();
		args.add(0);
		args.add(application.getCompanyName());	
		args.add(application.getTelephone());
		args.add(application.getContact());
		args.add(application.getAddress());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		Application application = new Application();
		application.setId(rs.getLong(ID));
		application.setCompanyName(rs.getString(COMPANYNAME));
		application.setTelephone(rs.getString(TELEPHONE));
		application.setContact(rs.getString(CONTACT));
		application.setAddress(rs.getString(ADDRESS));
		return application;
	}

	@Override
	public Map updateModelToMap(Object object) {
		Application application = (Application)object;
		Map map = new HashMap();
		map.put(ID, application.getId());
		map.put(COMPANYNAME, application.getCompanyName());
		map.put(TELEPHONE, application.getTelephone());
		map.put(CONTACT, application.getContact());
		map.put(ADDRESS, application.getAddress());
		return map;
	}
	

	public String insert(Application application){
		return super.insert(application);
	}
	
	public Application queryById(Long id){
		return (Application)super.queryById(id);
	}
	
	public int updateById(Long id, Application application) {
		return super.updateById(id, application);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}

}
